﻿using System;
using System.Collections.Generic;
using System.Net;
using System.Net.Http;
using System.Web.Http;
using System.Web.Mvc;
using Minion.Web.Data;
using Minion.Web.Root.Repositories;

namespace Minion.Web.Main.Controllers
{
    public class LocationController : ApiController
    {
        private readonly ILocationRepository _locationRepository;

        public LocationController(ILocationRepository locRepository)
        {
            _locationRepository = locRepository;
        }

        
        public IEnumerable<Location> Get()
        {
            return _locationRepository.GetAllLocationDetails();
        }

        
        public IEnumerable<Location> Get(double lat, double lon)
        {
            return _locationRepository.GetLocationDetails(lat, lon);
        }

        
        public HttpResponseMessage Post(Location value)
        {
            if (ModelState.IsValid)
            {
                _locationRepository.AddLocationItem(value);

                var response = new HttpResponseMessage(HttpStatusCode.Created);
                return response;

            }
            throw new HttpResponseException(HttpStatusCode.BadRequest);
        }

        
        public void Put(int id, [FromBody] string value)
        {
        }

        
        public void Delete(int id)
        {
        }

    }
}